<%@ page language="java" contentType="text/html; charset=utf-8"pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<title>商品管理</title>
		<link href="<c:url value="/resources/css/style.css" />" rel="stylesheet" type="text/css">
		<link href="<c:url value="/resources/css/default/easyui.css" />" rel="stylesheet" type="text/css">
		<link href="<c:url value="/resources/css/icon.css" />" rel="stylesheet" type="text/css">
		<script type="text/javascript" src="<c:url value="/resources/js/jquery-1.7.2.js" />"></script>
		<script type="text/javascript" src="<c:url value="/resources/js/jquery.easyui.min.js" />"></script>
		<script type="text/javascript" src="<c:url value="/resources/js/easyui-lang-zh_CN.js" />"></script>
		<script type="text/javascript">
			function getData(){
				var rows = [];
				rows.push({
					id: '0',
					product_sub_category_name: '---请选择---'
				});
				
				return rows;
			} 
			
			function showDiscount(value){
				if(value == 0){
					$("#lowDiscountTR").show();
				}else
					$("#lowDiscountTR").hide();
			}
			
			function getSubCategory(category){
				if(category.value == 0){
					$("#product_sub_category_id").combobox("loadData", getData());
				}else{
					$("#product_sub_category_id").combobox("clear");
					$("#product_sub_category_id")
						.combobox("loadData", getDanimicData(category.value));
					$("#product_sub_category_id").combobox("setValue", '0');
				}
			}
			
			function getDanimicData(categoryId){
				var data = '';
				$.ajax({
					url:'getSubCategory.do',
					data:{'categoryId':categoryId},
					type:'post',
					dataType:'json',
					async:false,
					cache:false,
					success:function(datas){
						data = datas;
					}
				});
				
				if (!data.topRows){	            	
	            	data.topRows = [];
	            	data.topRows.push({
						id: '0',
						product_sub_category_name: '---请选择---'
					});
	            	for(var i=0; i<data.length; i++){
	            		var row = data[i];
	            		data.topRows.push(row);
	            	}
	            }  
 
				data = $.extend(true,[],data.topRows);
				return data;
			}
			
			function onResetProduct(){
				$("#categoryId").combobox("setValue", '0');
				$("#product_sub_category_id").combobox("clear");
				$("#product_sub_category_id").combobox("loadData", getData());
				$("#product_sub_category_id").combobox("setValue", '0');
				
				$("#product_no").val('');
				$("#product_name").val('');
				
				$("#priceText").val('');
				$("#price").val('');
				
				$("#vip_price").val('');
				$("#vip_priceText").val('');
				
				$("#unit").val('');
				$("input[name='if_drug'][value=${abled}]").attr("checked",true);
				$("input[name='if_able_gift'][value=${abled}]").attr("checked",true); 
				$("input[name='if_able_discount'][value=${abled}]").attr("checked",true);
			
				$("#lowDiscountTR").show();
				$("#discount_range").val('');
				
				$("input[name='if_able_commission'][value=${abled}]").attr("checked",true);
				$("#remark").val('');
				
				$("input[name='needWorker'][value=${unabled}]").attr("checked",true);
				$("input[name='chessRoom'][value=${unabled}]").attr("checked",true);
				$("#lenOfMin").val('');
				$("#numOfHour").val('');
				$("input[name='plusService'][value=${unabled}]").attr("checked",true);
				$("#minOfAlert").val('');
				$("#minOfBuff").val('');
				
				$("#if_need_worker").val('');
				$("#if_chess_room").val('');
				$("#len_of_min").val('');
				$("#num_of_hour").val('');
				$("#if_plus_service").val('');
				$("#min_of_alert").val('');
				$("#min_of_buff").val('');
			}
			
			function onAddProduct(){
				var flag = "false";
				$.ajax({
					url:'checkProductNo.do',
					data:{'productNo':$.trim($("#product_no").val())},
					type:'post',
					dataType:'json',
					async:false,
					cache:false,
					success:function(data){
						flag = data;
					}
				});
				
				if(flag == 'true'){
					$.messager.alert('操作结果','商品编号已存在','warning');
					return false;
				}
				
				$("#price").val($("#priceText").val() * 100);
				$("#vip_price").val($("#vip_priceText").val() * 100);
				
				
				$("#if_need_worker").val($("input[name='needWorker']:checked").val());
				$("#if_chess_room").val($("input[name='chessRoom']:checked").val());
				$("#len_of_min").val($("#lenOfMin").val());
				$("#num_of_hour").val($("#numOfHour").val());
				$("#if_plus_service").val($("input[name='plusService']:checked").val());
				$("#min_of_alert").val($("#minOfAlert").val());
				$("#min_of_buff").val($("#minOfBuff").val());
				
				$("#addProductForm").submit();
			}
			
			$(function(){
				if('${result}' != null && '${result}' != ''){
					$.messager.alert('操作结果','${result}');
				}
			});
		</script>
	</head>
	
	<body>
		<div id="sss" class="easyui-tabs" style="width:700px;height:250px" data-options="fit:true">
			<div title="商品基本信息" style="padding:10px">
				<form name="addProductForm" id="addProductForm" method="post" action="addProduct">
					<table  style="text-align: center; border:1px;width:400px;">						
						<tr>
							<td align="right" style="height:28px;">商品类别：</td>
	    					<td align="left">
	    						<select  class="easyui-combobox" style="width:155px;"  name="categoryId" id="categoryId" data-options="required:true, panelHeight:'auto',onSelect:function(value){
	    							getSubCategory(value);
	    						}">
	    							<option value="0" selected="selected">---请选择---</option>
	    							<c:forEach var="code" items="${categoryList}">
	    								<option value="${code.id}">${code.product_category_name}</option>	
	    							</c:forEach>
	    						</select>
	    					</td>
						</tr>
						
						<tr>
							<td align="right" style="height:28px;">商品子类：</td>
	    					<td align="left">
	    						<select  class="easyui-combobox" style="width:155px;"  name="product_sub_category_id" id="product_sub_category_id" 
	    									data-options="required:true, panelHeight:'auto', valueField:'id', textField:'product_sub_category_name'">
	    							<option value="0" selected="selected">---请选择---</option>
	    						</select>
	    					</td>
						</tr>
						
						<tr>
							<td align="right" style="height:28px;">商品编号：</td>
	    					<td align="left">
	    						<input class="easyui-validatebox" style="width:150px;" type="text" name="product_no" id="product_no" required="true" />
	    					</td>
						</tr>
						
						<tr>
							<td align="right" style="height:28px;">商品名称：</td>
	    					<td align="left">
	    						<input class="easyui-validatebox" style="width:150px;" type="text" name="product_name" id="product_name" required="true" />
	    					</td>
						</tr>
						
						<tr>
							<td align="right" style="height:28px;">价格：</td>
	    					<td align="left">
	    						<input class="easyui-numberbox" style="width:150px;" type="text" name="priceText" id="priceText" data-options="required:true,precision:2,groupSeparator:','" />
	    						<input type="hidden" name="price" id="price" />
	    					</td>
						</tr>
						
						<tr>
							<td align="right" style="height:28px;">会员价：</td>
	    					<td align="left">
	    						<input class="easyui-numberbox" style="width:150px;" type="text" name="vip_priceText" id="vip_priceText" data-options="required:true,precision:2,groupSeparator:','" />
	    						<input type="hidden" name="vip_price" id="vip_price" />
	    					</td>
						</tr>
						
						<tr>
							<td align="right" style="height:28px;">单位：</td>
	    					<td align="left">
	    						<input class="easyui-validatebox" style="width:150px;" type="text" name="unit" id="unit" data-options="required:true" />
	    					</td>
						</tr>
						
						<tr>
							<td align="right" style="height:28px;">是否药水商品：</td>
	    					<td align="left">
	    						<input type="radio" name="if_drug" id="if_drug" value="${abled}" checked="checked" />是
	    						&nbsp;&nbsp;&nbsp;&nbsp;
	    						&nbsp;&nbsp;&nbsp;
	    						<input type="radio" name="if_drug" id="if_drug" value="${unabled}" />否
	    					</td>
						</tr>
						
						<tr>
							<td align="right" style="height:28px;">是否赠送：</td>
	    					<td align="left">
	    						<input type="radio" name="if_able_gift" id="if_able_gift" value="${abled}" checked="checked" />是
	    						&nbsp;&nbsp;&nbsp;&nbsp;
	    						&nbsp;&nbsp;&nbsp;
	    						<input type="radio" name="if_able_gift" id="if_able_gift" value="${unabled}" />否
	    					</td>
						</tr>
						
						<tr>
							<td align="right" style="height:28px;">是否打折：</td>
	    					<td align="left">
	    						<input type="radio" name="if_able_discount" id="if_able_discount" value="${abled}" checked="checked" onClick="showDiscount(this.value)"/>是
	    						&nbsp;&nbsp;&nbsp;&nbsp;
	    						&nbsp;&nbsp;&nbsp;
	    						<input type="radio" name="if_able_discount" id="if_able_discount" value="${unabled}" onClick="showDiscount(this.value)"/>否
	    					</td>
						</tr>
						
						<tr id="lowDiscountTR">
							<td align="right" style="height:28px;">最低折扣：</td>
	    					<td align="left">
	    						<input class="easyui-numberbox" style="width:150px;" type="text" name="discount_range" id="discount_range" data-options="precision:2,groupSeparator:','"/>
	    					</td>
						</tr>
						
						<tr>
							<td align="right" style="height:28px;">是否计算提成：</td>
	    					<td align="left">
	    						<input type="radio" name="if_able_commission" id="if_able_commission" value="${abled}" checked="checked" />是
	    						&nbsp;&nbsp;&nbsp;&nbsp;
	    						&nbsp;&nbsp;&nbsp;
	    						<input type="radio" name="if_able_commission" id="if_able_commission" value="${unabled}" />否
	    					</td>
						</tr>
						
						<tr>
							<td align="right" style="height:28px;">备注：</td>
	    					<td align="left">
	    						<textarea class="easyui-validatebox" style="width:250px;height: 100px;"  name="remark" id="remark" ></textarea>
	    					</td>
						</tr>
						
						<tr>
							<td colspan="2">
								<a href="javascript:void(0)" class="easyui-linkbutton" onclick="onAddProduct()">保存</a>
	    						<a href="javascript:void(0)" class="easyui-linkbutton" onclick="onResetProduct()">重置</a>
							</td>
						</tr>
					</table>
					
					<input type="hidden" name="if_need_worker" id="if_need_worker" />
					<input type="hidden" name="if_chess_room" id="if_chess_room" />
					<input type="hidden" name="len_of_min" id="len_of_min" />
					<input type="hidden" name="num_of_hour" id="num_of_hour" />
					<input type="hidden" name="if_plus_service" id="if_plus_service" />
					<input type="hidden" name="min_of_alert" id="min_of_alert" />
					<input type="hidden" name="min_of_buff" id="min_of_buff" />
				</form>
			</div>
			
			<div title="服务棋牌信息" style="padding:10px" >				
					<table  style="text-align: center; border:1px;width:400px;">
						<tr>
							<td align="right" style="height:28px;">是否需要技师：</td>
	    					<td align="left">
	    						<input type="radio" name="needWorker" id="needWorker" value="${abled}" />是
	    						&nbsp;&nbsp;&nbsp;&nbsp;
	    						&nbsp;&nbsp;&nbsp;
	    						<input type="radio" name="needWorker" id="needWorker" value="${unabled}" checked="checked" />否
	    					</td>
						</tr>
						
						<tr>
							<td align="right" style="height:28px;">是否棋牌类：</td>
	    					<td align="left">
	    						<input type="radio" name="chessRoom" id="chessRoom" value="${abled}" />是
	    						&nbsp;&nbsp;&nbsp;&nbsp;
	    						&nbsp;&nbsp;&nbsp;
	    						<input type="radio" name="chessRoom" id="chessRoom" value="${unabled}" checked="checked" />否
	    					</td>
						</tr>
						
						<tr>
							<td align="right" style="height:28px;">时长：</td>
	    					<td align="left">
	    						<input class="easyui-numberbox" style="width:150px;" type="text" name="lenOfMin" id="lenOfMin" />
	    					</td>	    					
						</tr>
						
						<tr>
							<td align="right" style="height:28px;">钟数：</td>
	    					<td align="left">
	    						<input class="easyui-numberbox" style="width:150px;" type="text" name="numOfHour" id="numOfHour"  />
	    					</td>	    					
						</tr>
						
						<tr>
							<td align="right" style="height:28px;">是否加钟：</td>
	    					<td align="left">
	    						<input type="radio" name="plusService" id="plusService" value="${abled}" />是
	    						&nbsp;&nbsp;&nbsp;&nbsp;
	    						&nbsp;&nbsp;&nbsp;
	    						<input type="radio" name="plusService" id="plusService" value="${unabled}" checked="checked" />否
	    					</td>
						</tr>
						
						<tr>
							<td align="right" style="height:28px;">提醒时间(分)：</td>
	    					<td align="left">
	    						<input class="easyui-numberbox" style="width:150px;" type="text" name="minOfAlert" id="minOfAlert"  />
	    					</td>	    					
						</tr>
										
						<tr>
							<td align="right" style="height:28px;">超时(分)：</td>
	    					<td align="left">
	    						<input class="easyui-numberbox" style="width:150px;" type="text" name="minOfBuff" id="minOfBuff"  />
	    					</td>	    					
						</tr>
					</table>
				</div>
			</div>
	</body>
</html>